use crate::public::{
  KeybdKey::{self, *},
  MouseButton::{self, *},
};

impl From<KeybdKey> for u64 {
  // https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes?redirectedfrom=MSDN
  fn from(key: KeybdKey) -> u64 {
    match key {
      BackspaceKey => 0x08,
      TabKey => 0x09,
      EnterKey => 0x0d,
      EscapeKey => 0x1b,
      SpaceKey => 0x20,
      PageUpKey => 0x21,
      PageDownKey => 0x22,
      EndKey => 0x23,
      HomeKey => 0x24,
      LeftKey => 0x25,
      UpKey => 0x26,
      RightKey => 0x27,
      DownKey => 0x28,
      InsertKey => 0x2d,
      DeleteKey => 0x2e,
      Numrow0Key => 0x30,
      Numrow1Key => 0x31,
      Numrow2Key => 0x32,
      Numrow3Key => 0x33,
      Numrow4Key => 0x34,
      Numrow5Key => 0x35,
      Numrow6Key => 0x36,
      Numrow7Key => 0x37,
      Numrow8Key => 0x38,
      Numrow9Key => 0x39,
      AKey => 0x41,
      BKey => 0x42,
      CKey => 0x43,
      DKey => 0x44,
      EKey => 0x45,
      FKey => 0x46,
      GKey => 0x47,
      HKey => 0x48,
      IKey => 0x49,
      JKey => 0x4a,
      KKey => 0x4b,
      LKey => 0x4c,
      MKey => 0x4d,
      NKey => 0x4e,
      OKey => 0x4f,
      PKey => 0x50,
      QKey => 0x51,
      RKey => 0x52,
      SKey => 0x53,
      TKey => 0x54,
      UKey => 0x55,
      VKey => 0x56,
      WKey => 0x57,
      XKey => 0x58,
      YKey => 0x59,
      ZKey => 0x5a,
      LSuper => 0x5b,
      RSuper => 0x5c,
      Numpad0Key => 0x60,
      Numpad1Key => 0x61,
      Numpad2Key => 0x62,
      Numpad3Key => 0x63,
      Numpad4Key => 0x64,
      Numpad5Key => 0x65,
      Numpad6Key => 0x66,
      Numpad7Key => 0x67,
      Numpad8Key => 0x68,
      Numpad9Key => 0x69,
      F1Key => 0x70,
      F2Key => 0x71,
      F3Key => 0x72,
      F4Key => 0x73,
      F5Key => 0x74,
      F6Key => 0x75,
      F7Key => 0x76,
      F8Key => 0x77,
      F9Key => 0x78,
      F10Key => 0x79,
      F11Key => 0x7a,
      F12Key => 0x7b,
      F13Key => 0x7c,
      F14Key => 0x7d,
      F15Key => 0x7e,
      F16Key => 0x7f,
      F17Key => 0x80,
      F18Key => 0x81,
      F19Key => 0x82,
      F20Key => 0x83,
      F21Key => 0x84,
      F22Key => 0x85,
      F23Key => 0x86,
      F24Key => 0x87,
      NumLockKey => 0x90,
      ScrollLockKey => 0x91,
      CapsLockKey => 0x14,
      LShiftKey => 0xa0,
      RShiftKey => 0xa1,
      LControlKey => 0xa2,
      RControlKey => 0xa3,
      LAltKey => 0xa4,
      RAltKey => 0xa5,
      BrowserBackKey => 0xa6,
      BrowserForwardKey => 0xa7,
      BrowserRefreshKey => 0xa8,
      VolumeMuteKey => 0xad,
      VolumeDownKey => 0xae,
      VolumeUpKey => 0xaf,
      MediaNextTrackKey => 0xb0,
      MediaPrevTrackKey => 0xb1,
      MediaStopKey => 0xb2,
      MediaPlayPauseKey => 0xb3,
      BackquoteKey => 0xc0,
      SlashKey => 0xbf,
      BackslashKey => 0xdc,
      CommaKey => 0xbc,
      PeriodKey => 0xbe,
      MinusKey => 0xbd,
      QuoteKey => 0xde,
      SemicolonKey => 0xba,
      LBracketKey => 0xdb,
      RBracketKey => 0xdd,
      EqualKey => 0xbb,
      OtherKey(code) => code,
      CommandKey => todo!(),
    }
  }
}

impl From<u64> for KeybdKey {
  // https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes?redirectedfrom=MSDN
  fn from(code: u64) -> KeybdKey {
    match code {
      0x08 => BackspaceKey,
      0x09 => TabKey,
      0x0d => EnterKey,
      0x1b => EscapeKey,
      0x20 => SpaceKey,
      0x21 => PageUpKey,
      0x22 => PageDownKey,
      0x23 => EndKey,
      0x24 => HomeKey,
      0x25 => LeftKey,
      0x26 => UpKey,
      0x27 => RightKey,
      0x28 => DownKey,
      0x2d => InsertKey,
      0x2e => DeleteKey,
      0x30 => Numrow0Key,
      0x31 => Numrow1Key,
      0x32 => Numrow2Key,
      0x33 => Numrow3Key,
      0x34 => Numrow4Key,
      0x35 => Numrow5Key,
      0x36 => Numrow6Key,
      0x37 => Numrow7Key,
      0x38 => Numrow8Key,
      0x39 => Numrow9Key,
      0x41 => AKey,
      0x42 => BKey,
      0x43 => CKey,
      0x44 => DKey,
      0x45 => EKey,
      0x46 => FKey,
      0x47 => GKey,
      0x48 => HKey,
      0x49 => IKey,
      0x4a => JKey,
      0x4b => KKey,
      0x4c => LKey,
      0x4d => MKey,
      0x4e => NKey,
      0x4f => OKey,
      0x50 => PKey,
      0x51 => QKey,
      0x52 => RKey,
      0x53 => SKey,
      0x54 => TKey,
      0x55 => UKey,
      0x56 => VKey,
      0x57 => WKey,
      0x58 => XKey,
      0x59 => YKey,
      0x5a => ZKey,
      0x5b => LSuper,
      0x5c => RSuper,
      0x60 => Numpad0Key,
      0x61 => Numpad1Key,
      0x62 => Numpad2Key,
      0x63 => Numpad3Key,
      0x64 => Numpad4Key,
      0x65 => Numpad5Key,
      0x66 => Numpad6Key,
      0x67 => Numpad7Key,
      0x68 => Numpad8Key,
      0x69 => Numpad9Key,
      0x70 => F1Key,
      0x71 => F2Key,
      0x72 => F3Key,
      0x73 => F4Key,
      0x74 => F5Key,
      0x75 => F6Key,
      0x76 => F7Key,
      0x77 => F8Key,
      0x78 => F9Key,
      0x79 => F10Key,
      0x7a => F11Key,
      0x7b => F12Key,
      0x7c => F13Key,
      0x7d => F14Key,
      0x7e => F15Key,
      0x7f => F16Key,
      0x80 => F17Key,
      0x81 => F18Key,
      0x82 => F19Key,
      0x83 => F20Key,
      0x84 => F21Key,
      0x85 => F22Key,
      0x86 => F23Key,
      0x87 => F24Key,
      0x90 => NumLockKey,
      0x91 => ScrollLockKey,
      0x14 => CapsLockKey,
      0xa0 => LShiftKey,
      0xa1 => RShiftKey,
      0xa2 => LControlKey,
      0xa3 => RControlKey,
      0xa4 => LAltKey,
      0xa5 => RAltKey,
      0xa6 => BrowserBackKey,
      0xa7 => BrowserForwardKey,
      0xa8 => BrowserRefreshKey,
      0xad => VolumeMuteKey,
      0xae => VolumeDownKey,
      0xaf => VolumeUpKey,
      0xb0 => MediaNextTrackKey,
      0xb1 => MediaPrevTrackKey,
      0xb2 => MediaStopKey,
      0xb3 => MediaPlayPauseKey,
      0xc0 => BackquoteKey,
      0xbf => SlashKey,
      0xdc => BackslashKey,
      0xbc => CommaKey,
      0xbe => PeriodKey,
      0xbd => MinusKey,
      0xde => QuoteKey,
      0xba => SemicolonKey,
      0xdb => LBracketKey,
      0xdd => RBracketKey,
      0xbb => EqualKey,
      _ => OtherKey(code),
    }
  }
}

impl From<MouseButton> for u32 {
  fn from(button: MouseButton) -> u32 {
    match button {
      LeftButton => 0x01,
      RightButton => 0x02,
      MiddleButton => 0x04,
      X1Button => 0x05,
      X2Button => 0x06,
      OtherButton(code) => code,
    }
  }
}
